package com.lixixi.tingshu.search.listener;

import com.lixixi.tingshu.common.constant.KafkaConstant;
import com.lixixi.tingshu.search.service.SearchAlbumInfoService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class AlbumListener {

	@Autowired
	SearchAlbumInfoService searchAlbumInfoService;

	@KafkaListener(groupId = "upperAlbum", topics = KafkaConstant.QUEUE_ALBUM_UPPER)
	void upperAlbum(String albumId) {
		if (log.isDebugEnabled())
		{
			log.info("上架专辑:{}", albumId);
		}
		if (StringUtils.isNotBlank(albumId))
			searchAlbumInfoService.upperAlbum(Long.parseLong(albumId));
	}

	@KafkaListener(groupId = "lowerAlbum", topics = KafkaConstant.QUEUE_ALBUM_LOWER)
	void lowerAlbum(String albumId) {
		if (log.isDebugEnabled())
		{
			log.info("下架专辑:{}", albumId);
		}
		if (StringUtils.isNotBlank(albumId))
			searchAlbumInfoService.lowerAlbum(Long.parseLong(albumId));
	}
}
